<template>
	<view>
		<view class="pay-price">
			<view class="unit">￥</view>
			<view class="price">306.00</view>
		</view>
		<view class="count-down">
			支付剩余时间：
			<count-down :date="orderInfo.expirationTime" separator="zh" theme="text" />
		</view>
		<view class="payment">
			<view class="title">支付方式</view>
			<view class="item" v-for="(item, index) in payMethodList" :key="index">
				<view class="left">
					<image src="../../static/icon-31.png"></image>
					<view>微信支付</view>
				</view>
				<view class="right">
					<image src="../../static/pay_selected.png"></image>
				</view>
			</view>
			<!-- <view>线下支付</view>
			<view>好友代付</view> -->
		</view>
		<view class="footer-fixed">
			<view class="btn-wrapper">
				<view class="pay" @click="query()">确认支付</view>
				<view class="nopay" @click="unquery()">暂不支付</view>
			</view>
		</view>
	</view>
</template>

<script>
	import CountDown from '@/components/countdown'
	
	import { Order } from '@/utils/model/order-model.js';
	var order = new Order();
	import { Pay } from '@/utils/model/pay-model.js';
	var pay = new Pay();
	
	export default {
		components: {
		  CountDown
		},
		data() {
			return {
				payMethodList: [{
					id: 1,
					name: '微信支付'
				}],
				orderId: 0,
				orderInfo: {
					expirationTime: ''
				}
			}
		},
		onLoad(options) {
			// 记录订单ID
			this.orderId = Number(options.id)
			// 获取收银台信息
			this.getCashierInfo()
		},
		
		methods: {
			// 获取收银台信息
			getCashierInfo() {
				const that = this; 
				order.getUnpaidDetail(that.orderId).then((res) => {
					if(res.code == 1){
						that.orderInfo = res.data.detail
					}else{
						uni.showModal({
							title: '友情提示',
							content: res.msg,
							showCancel: false,
							success() {
								uni.navigateBack()
							}
						}) 
					}
				}).catch((err) => {
				})
			},
			// 确认支付
			query() {
				/* // 提交到后端API
				CashierApi.orderPa(app.orderId, {
					method: app.curPaymentItem.method,
					client: app.platform,
					extra: app.getExtraAsUnify(app.curPaymentItem.method)
				  })
				  .then(result => app.onSubmitCallback(result))
				  .finally(err => setTimeout(() => app.disabled = false, 10)) */
				  pay.getSignature(this.orderId).then((res) => {
				  	console.log(res)
				  	console.log('_execPay_execPay_execPay_execPay_execPay_execPay_execPay_execPay_execPay_execPay_execPay_execPay')
				  	if(res.code == 1){
						let signature = res.data.signature
				  		var timeStamp = signature.timeStamp;
				  		if (timeStamp) {
				  			pay.execPay(signature, statusCode => {
								console.log('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')
				  				console.log(1)
								console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
				  				if(statusCode == 1){
				  					uni.showToast({
				  						title:'支付成功',
				  						icon:'none'
				  					})
				  				}else{
				  					uni.showToast({
				  						title:'支付失败',
				  						icon:'none'
				  					})
				  				}
				  				uni.redirectTo({
				  					url:'/pages/order/detail?id=' + this.orderId + '&from=orderadd'
				  				}) 
				  			})
				  		}else{
				  		} 
				  	}
				  }).catch((err) => {
				  	console.log(err)
				  	console.log('ccccccccccccccccccccccccccc')
				  })
			},
			unquery(){
				uni.redirectTo({
					url:'/pages/order/detail?id='+this.orderId
				})
			}
			
		}
	}
</script>

<style>
	page{
		background-color: #F5F5F5;
	}
</style>
 
<style scoped lang="scss">
	@import '~@/pages/order/pay.scss';
</style>